classdef SimulationProgressBarSingleton < Singleton & ClockHandler
    %PROGRESSBARSINGLETON Summary of this class goes here
    %   Detailed explanation goes here
    
   methods(Static)
      function obj = instance(should_reinit)
         persistent unique_instance;
         should_reinit = (nargin>0);
         if isempty(unique_instance) || (should_reinit==true)
            unique_instance = SimulationProgressBarSingleton();
         end
         obj = unique_instance;
      end
   end
    
     properties
         progress_bar_handle = [];
         progress_bar_max_count = 0;
    end
   
    methods
        function obj = SimulationProgressBarSingleton()
            gui_active(1);
            obj.progress_bar_handle = progressbar( [],0,'simulation progress' ); 
            params = ParamsSingleton.instance();
            obj.progress_bar_max_count = params.simulation_time_in_msec / params.clock_tick_delta_in_msec;
            %register on clock tick
            ck = ClockSingleton.instance();
            ck.register_for_clock_ticks(obj);
        end
        
        function clock_tick_handler(obj)
            progressbar(obj.progress_bar_handle,1/obj.progress_bar_max_count); 
        end
        
    end
    
end

